package com.mgface.framework.health;

import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.Date;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.actuate.health.Health;
import org.springframework.boot.actuate.health.HealthIndicator;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;

@Component("sbdHealth")
public class SBDHealth implements HealthIndicator{
	private static final Logger log = LogManager.getLogger(SBDHealth.class);
	@Autowired
	private ApplicationContext applicationContext;

	@Override
	public Health health() {
		Instant instant = new Date(applicationContext.getStartupDate()).toInstant();
		LocalDateTime time = LocalDateTime.ofInstant(instant, ZoneId.of("Asia/Shanghai"));
		String times = time.format(DateTimeFormatter.ISO_LOCAL_DATE_TIME);
		int logicProcessors = Runtime.getRuntime().availableProcessors();
		log.info("ApplicationContext启动时间:{}",times);
		return Health.up().withDetail("启动时间", times).withDetail("逻辑处理器核",logicProcessors).build();
	}

}
